﻿using System;
using System.Linq;
using UnityEditor;
using UnityEngine;

public class RiverUnderGroundEditor : ShaderGUI
{

    public enum CullMode
    {
        CULL_NONE = 0,
        CULL_FRONT = 1,
        CULL_BACK = 2,
    }

    public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
    {
        Shader.SetGlobalFloat(ShaderConst.SID_RoleDistance, 0);
        Material targetMat = materialEditor.target as Material;

        base.OnGUI(materialEditor, properties);

        targetMat.EnableKeyword("USE_TEXTURE");
        properties.ToList().ForEach(prop =>
        {
            if (prop.name == "_MainTex")
            {
                bool USE_TEXTURE = prop.textureValue != null;
                if (USE_TEXTURE)
                    targetMat.EnableKeyword("USE_TEXTURE");
                else
                    targetMat.DisableKeyword("USE_TEXTURE");
            }
        });

        //cullMode
        var cullMode = FindProperty("_Cull", properties);
        GUILayout.BeginHorizontal();
        GUILayout.Label(new GUIContent("Cull", "CullMode"), GUILayout.Width(120));
        var cull = (CullMode)cullMode.floatValue;
        cull = (CullMode)EditorGUILayout.Popup((int)cull, Enum.GetNames(typeof(CullMode)));
        GUILayout.EndHorizontal();

        if (EditorGUI.EndChangeCheck())
        {
            //cullMode
            cullMode.floatValue = (float)cull;
            targetMat.SetInt("_Cull", (int)cull);
        }





    }

}